﻿using System.Text;

namespace Wulong.Phone.Dianping.Utils
{
    public class BaiduMapHelper
    {
        public static string TransitMapHtml(string cityName, string fromAddr, string toAddr)
        {
            const string cityFormat = "		map.setCurrentCity(\"{0}\");";
            const string addrFormat = "		gc.getPoint(\"{0}\", function(point){{";
            const string endFormat = "}}}}, \"{0}\"); ";
            var sb = new StringBuilder();
            sb.AppendLine("<html>");
            sb.AppendLine("	<head>");
            //sb.AppendLine("	    <meta name=\"viewreport\" content=\"initial-scale=1.0, user-scalable=no\">");
            sb.AppendLine("		<style type=\"text/css\">");
            sb.AppendLine("			html{");
            sb.AppendLine("				height: 100%");
            sb.AppendLine("			}");
            sb.AppendLine("			body{");
            sb.AppendLine("				height: 100%;");
            sb.AppendLine("				margin: 0px;");
            sb.AppendLine("				padding:0px;");
            sb.AppendLine("			}");
            sb.AppendLine("			#container{");
            sb.AppendLine("				height: 60%");
            sb.AppendLine("			}");
            sb.AppendLine("		</style>");
            sb.AppendLine("		<script type=\"text/javascript\" src=\"http://api.map.baidu.com/api?v=1.2\"></script>");
            sb.AppendLine("	</head>");
            sb.AppendLine("	<body>");
            sb.AppendLine(" <div id=\"container\"></div>");
            sb.AppendLine(" <div id=\"results\" style=\"font-size:13px;margin-top:10px;\"></div>");
            sb.AppendLine("	</body>");
            sb.AppendLine("</html>");
            sb.AppendLine("	<script type=\"text/javascript\">");
            sb.AppendLine("		var map = new BMap.Map(\"container\");");
            sb.AppendLine("		        map.centerAndZoom(new BMap.Point(116.404, 39.915), 15);");
            sb.AppendLine(string.Format(cityFormat, cityName));
            //sb.AppendLine("		var gc = new BMap.Geocoder();");
            //sb.AppendFormat(addrFormat, toAddr);
            //sb.AppendLine();
            //sb.AppendLine("		     if (point) {");
            //sb.AppendLine("		        map.centerAndZoom(point, 15);");
            //sb.AppendLine("		        map.addOverlay(new BMap.Marker(point));");
            //sb.AppendFormat(endFormat, cityName);
            //sb.AppendLine();
            sb.AppendLine("     var transit = new BMap.TransitRoute(map, {");
            sb.AppendLine("         renderOptions: {map: map, panel: \"results\"}");
            sb.AppendLine("     });");
            sb.AppendFormat("    transit.search(\"{0}\", \"{1}\");", fromAddr, toAddr);
            sb.AppendLine();
            //sb.AppendLine("		map.addControl(new BMap.NavigationControl);");
            //sb.AppendLine("		map.addControl(new BMap.ScaleControl);");
            //sb.AppendLine("		map.addControl(new BMap.OverviewMapControl);");
            //sb.AppendLine("		map.addControl(new BMap.MapTypeControl);");
            sb.AppendLine("	</script>");

            return sb.ToString();
        }
    }
}
